package com.stary.code.util;

import java.sql.Connection;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.jdbc.ScriptRunner;

/**
 * <p>mybatis 读取并执行sql</p>
 * @author stary {@link stary1993@qq.com}
 * @since 2018-10-24
 */
public class SqlFileExecutor {

	/**
	 * 执行sql脚本
	 * @param conn 连接
	 * @param sqlFile sql脚本文件
	 * @throws Exception
	 */
	public static void execute(Connection conn, String sqlFile) throws Exception {
		ScriptRunner runner = new ScriptRunner(conn);
		runner.setLogWriter(null);
		runner.runScript(Resources.getResourceAsReader(sqlFile));	
	}
	
}